﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace XSTDZ.ERP.WebApp.Models.Extension
{
    /// <summary>
    /// 字符串扩展
    /// </summary>
    public static class StringExtenstion
    {
        /// <summary>
        /// 判断是否为空
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsEmpty(this string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return true;
            }
            if (str.Trim().ToUpper() == "undefined".ToUpper())
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 判断是否是时间格式
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsData(this string str)
        {
            if (str.IsEmpty())
            {
                return false;
            }
            DateTime dt;
           return DateTime.TryParse(str, out dt);
        }
        /// <summary>
        /// 根据全路径返回文件名称
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetFileNameFormDir(this string str)
        {
            if (str.IsEmpty())
            {
                return "";
            }
            int po = str.LastIndexOf("\\");
          return  str.Substring(po+1, str.Length - po-1 );

        }
    }
}